From: Joey Hess Date: Thu, 30 Jan 2025 20:51:42 +0000 (-0400) Subject: fix truncateFilePath edge case on windows X-Git-Tag: archive/raspbian/10.20250416-2+rpi1~1^2~6^2~178 X-Git-Url: https://dgit.raspbian.org/%22http:/www.example.com/cgi/%22https:/www.github.com/%22bookmarks:///%22http:/www.example.com/cgi/%22https:/www.github.com/%22bookmarks:/?a=commitdiff_plain;h=773115fd5f9334855b138323b74ca572695208a0;p=git-annex.git fix truncateFilePath edge case on windows If the filepath starts with something that is not valid utf-8, it would have returned "". And if the filepath was all non-valid utf-8, it would also return "". --- diff --git a/Utility/FileSystemEncoding.hs b/Utility/FileSystemEncoding.hs index b4497f30af..cf9355ccd5 100644 --- a/Utility/FileSystemEncoding.hs +++ b/Utility/FileSystemEncoding.hs @@ -157,10 +157,13 @@ truncateFilePath n = toRawFilePath . reverse . go [] n go coll cnt bs | cnt <= 0 = coll | otherwise = case S8.decode bs of - Just (c, x) | c /= S8.replacement_char -> - let x' = fromIntegral x - in if cnt - x' < 0 - then coll - else go (c:coll) (cnt - x') (S8.drop 1 bs) + Just (c, x) + | c /= S8.replacement_char -> + let x' = fromIntegral x + in if cnt - x' < 0 + then coll + else go (c:coll) (cnt - x') (S8.drop 1 bs) + | otherwise -> + go ('_':coll) (cnt - 1) (S8.drop 1 bs) _ -> coll #endif